<?php

if(!defined('IN_ECS'))
{
	die('Hacking attempt');
}

function set_admin_session($user_id,$username,$action_list,$last_time)
{
	$_SESSION['admin_id'] 		= $user_id;
	$_SESSION['admin_name'] 	= $username;
	$_SESSION['action_list'] 	= $action_list;
	$_SESSION['last_check'] 	= $last_time;
}

function make_json_error($msg)
{
	make_json_response('',1,$msg);
}

function make_json_response($content='',$error='0',$message='',$append=array())
{
	include_once ROOT_PATH . 'includes/cls_json.php';
	
	$json = new JSON;
	
	$res = array('error'=>$error,'message'=>$message,'content'=>$content);
	
	if(!empty($append))
	{
		foreach($append as $key=>$val)
		{
			$res[$key] = $val;
		}
	}
	$val = $json->encode($res);
	
	exit($val);
}

function sys_msg($msg_detail,$msg_type=0,$links=array(),$auto_redirect = true)
{
	if(count($links) == 0)
	{
		$links[0]['text'] = $GLOBALS['_LANG']['go_back'];
		$links[0]['href'] = 'javascript:history.go(-1)';
	}
	
//	assign_query_info();
	
	$GLOBALS['smarty']->assign('ur_here',$GLOBALS['_LANG']['system_message']);
	$GLOBALS['smarty']->assign('msg_detail',$msg_detail);
	$GLOBALS['smarty']->assign('msg_type',$msg_type);
	$GLOBALS['smarty']->assign('links',$links);
	$GLOBALS['smarty']->assign('default_url',$links[0]['href']);
	$GLOBALS['smarty']->assign('auto_redirect',$auto_redirect);
	
	$GLOBALS['smarty']->display('message.html');
	
	exit;
	
}

function admin_priv($priv_str,$msg_type='',$msg_output=true)
{
	global $_LANG;
	
	if($_SESSION['action_list'] == 'all')
	{
		return true;
	}
	
	if(strpos(',', $_SESSION['action_list'] .',',','.$priv_str.',') === false)
	{
		$link[]=  array('text'=>$_LANG['go_back'],'href'=>'javascript:history.back(-1)');
		if($msg_output)
		{
			sys_msg($_LANG['priv_error'], 0,$link);
		}
		return false;
	}
	else 
	{
		return true;
	}
}


